package pe.gob.osinergmin.interfase_siaf.dac.common.dao.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class Conexion {
   
   
    @SuppressWarnings("finally")
	public static synchronized Connection getConexion(String className,String url,String user,String password) 
    {
    	Connection cn = null;
          try 
        {
          Class.forName(className);
          return cn = DriverManager.getConnection(url, user, password);
        } 
        catch (Exception e) 
        {
           return cn = null;
        }finally 
        {
            return cn;
        }
       
    }
    
    @SuppressWarnings("finally")
   	public static synchronized Connection getConexionODBC(String className,String url,String userName,String password) 
       {
       	Connection cn = null;
             try 
           {
             Class.forName(className);
             return cn = DriverManager.getConnection(url,userName,password);
           } 
           catch (Exception e) 
           {
              return cn = null;
           }finally 
           {
               return cn;
           }
          
       }
         
    public static synchronized void cerrarPst(PreparedStatement pst) 
    { 
         try
        {
           pst.close();
        }
        catch(Exception e)
        {
         System.err.print(e.toString());   
        }
    }
    
    
    public static synchronized void cerrarConexion(Connection cn) 
      {
        try
        {        	
            cn.close();
        } 
        catch (Exception e) 
        {
          System.err.print(e.toString());    
        }
    }
    
    public static synchronized void deshacerCambios(Connection cn) 
      {
        try
        {
            cn.rollback();
        }
        catch (Exception e)
        {
         System.err.print(e.toString());     
        }
    }
    
    
   
   
}
